package cat.joronya.supermanager.service;

import org.apache.http.impl.client.DefaultHttpClient;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.RemoteException;
import android.util.Log;
import cat.joronya.supermanager.Supermanager;
import cat.joronya.supermanager.market.MarketProvider;
import cat.joronya.supermanager.privateleague.PrivateLeagueProvider;
import cat.joronya.supermanager.team.MyTeamDetailProvider;
import cat.joronya.supermanager.team.MyTeamsProvider;

/**
 * Reb Intents del SupermanagerHelper i els va encuant
 * i executant ordenadament en un thread apart per no
 * bloquejar aqui.
 * 
 * @author pol
 */
public class SupermanagerService extends IntentService
{
	// tag per log
	private static final String TAG = "supermanager";
	
	// wake lock to keep service awake on full update operation called from
	// alarm service
	private PowerManager.WakeLock wl;
	
	// guardem la sessio en tota la tongada de peticions a la
	// mateixa instancia de service
	DefaultHttpClient client = null;
	int status = Supermanager.OTHER_ERROR_STATUS;
	Integer jornada = null;
	Integer nextJornada = null;
	Messenger messenger = null;
	
	public SupermanagerService()
	{
		super("SupermanagerService");
	}
	
	/**
	 * Respon a les diferents demandes de les Activities, el IntentService
	 * ja s'encarrega de la cua i de passar-nos intents un a un. Tambe fa
	 * que s'executi en un worker thread.
	 */
	@Override
	protected void onHandleIntent(Intent intent) 
	{
		// mirem que ens demanen executar
		Uri uri = intent.getData();
		
		// uep, no tenim uri?? no cal fer res!
		if( !"login".equals(intent.getAction()) && uri == null)
		{
			Log.d(TAG, "no estem al login ni ens passen Uri, llavors no fem res");
			return;
		}
		
		// recuperem el messenger per notificar l'activity que ens ha cridat
		messenger = (Messenger)intent.getExtras().get("cat.joronya.supermanager.messenger"); 
		
        // checkejar connectivitat per si venim del update matiner, llavors 
        // no s'ha fet check previ a la crida al service.
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        boolean online = cm.getActiveNetworkInfo().isConnectedOrConnecting();
		if( !online )
		{
			Log.d(TAG, "no tenim connectivitat, accio descartada");
			return;
		}


		// Cal fer init i login en dos casos:
		// -si es la primera accio i no tenim sessio
		// -si es el login 
		if( client == null || "login".equals(intent.getAction()) )
		{
			// inicialitzem la sessio
			InitSync initSync = new InitSync(this);
			client = initSync.execute();
			status = initSync.status;
			
			// si dona error de conectivitat
			if( initSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( initSync.status == Supermanager.CLOSED_STATUS )
			{
				// cridar el handler amb el status de closed error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CLOSED_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Close web error!");
				return;
			}
			else if( initSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			
			if( client == null )
			{
				Log.e(TAG, "Error initializing network connection");
				return;
			}
			
			// recuperem username i password pel login
			String username = intent.getStringExtra("cat.joronya.supermanager.login.username");
			String password = intent.getStringExtra("cat.joronya.supermanager.login.password");

			// fem login
			LoginSync loginSync = new LoginSync(this, client);
			loginSync.execute(username,password);
			status = loginSync.status;
			
			// si dona error d'AUTH no guardem i mostrem Toast d'error
			if( loginSync.status == Supermanager.AUTH_ERROR_STATUS )
			{
				// cridar el handler amb el status d'auth error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, loginSync.status); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Authentication error!");
				return;
			}
			else if( loginSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( loginSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( loginSync.status == Supermanager.OPEN_NO_CHANGES_STATUS )
			{
				// nomes notifiquem de l'estat si feiem login, sino continuem
				if( "login".equals(intent.getAction()) )
				{
					// cridar el handler amb el status de open with no changes
					Message msg = Message.obtain(); 
					Bundle data = new Bundle(); 
					data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OPEN_NO_CHANGES_STATUS); 
					msg.setData(data); 
                
					try{ 
						messenger.send(msg); 
					}catch(RemoteException e){ 
						Log.e(TAG, "Error sending auth error to Activity caller"); 
					} 
				}
				Log.d(TAG,"Status Open with no changes");
			}
			else if( loginSync.status == Supermanager.OPEN_STATUS )
			{
				// nomes notifiquem de l'estat si feiem login, sino continuem
				if( "login".equals(intent.getAction()) )
				{
					// cridar el handler amb el status de open
					Message msg = Message.obtain(); 
					Bundle data = new Bundle(); 
					data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OPEN_STATUS); 
					msg.setData(data); 
                
					try{ 
						messenger.send(msg); 
					}catch(RemoteException e){ 
						Log.e(TAG, "Error sending auth error to Activity caller"); 
					} 
				}
				Log.d(TAG,"Status Open");
			}
			else if( loginSync.status == Supermanager.CLOSED_STATUS )
            {
				// nomes notifiquem de l'estat si feiem login, sino continuem
				if( "login".equals(intent.getAction()) )
				{
					// cridar el handler amb el status de open
					Message msg = Message.obtain(); 
					Bundle data = new Bundle(); 
					data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CLOSED_STATUS); 
					msg.setData(data); 
                
					try{ 
						messenger.send(msg); 
					}catch(RemoteException e){ 
						Log.e(TAG, "Error sending auth error to Activity caller"); 
					} 
				}
				Log.d(TAG,"Status Closed");
            }

			// Quan tancada web, no tenim jornada
			try
			{
				jornada = new Integer(loginSync.jornada);
				nextJornada = new Integer(loginSync.nextJornada);
				Log.d(TAG,"LoginSyn.jornada: "+jornada+", nextJornada: "+nextJornada);
			}
			catch(Exception e) {}

			// altrament guardem dades home i estat
			loginSync.onPostExecute(Supermanager.Home.CONTENT_URI);
			
			// si nomes feiem login sortiem
			if( "login".equals(intent.getAction()) )
				return;
		}
		
		// tractem el sync de totes les taules
		if( Intent.ACTION_SYNC.equals(intent.getAction()) )
		{
			Log.d(TAG, "SupermanagerService starting fullUpdate");
			
			// wake lock to keep service awake
			PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
            wl.acquire();
            
			boolean showNotifications = intent.getBooleanExtra("cat.joronya.supermanager.fullupdate.shownotifications", false);
			
			// update the tables 
			FullContentUpdater contentUpdater = 
				new FullContentUpdater(this, client, jornada, nextJornada, status, showNotifications); 
			contentUpdater.update();
			
			// release wake lock
			wl.release();
			
			return;
		}
		
		// tractem la notificacio de tancament de canvis
		if( Intent.ACTION_VIEW.equals(intent.getAction()))
		{
			Log.d(TAG, "SupermanagerService start closed changes notify");
			
			// wake lock to keep service awake
			PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
            wl.acquire();
            
            // check for changes
            ClosedChangesNotification ccn = new ClosedChangesNotification(this);
            ccn.chekForNotification();
            
            // release wake lock
			wl.release();
			
			return;
		}
		
		// mirem si es algo referent a les lligues privades
		// uri de /privateleagues -> nomes updatem els llistat, no mirem action
		if( PrivateLeagueProvider.uriMatcher.match(uri) == PrivateLeagueProvider.PRIVATE_LEAGUES 
			&& Intent.ACTION_GET_CONTENT.equals(intent.getAction()) )
		{
			// get private leagues
			PrivateLeaguesSync plSync = new PrivateLeaguesSync(this, client);
			// si no hi ha error guardem a db
			plSync.execute();
			
			if( plSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( plSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( plSync.status == Supermanager.PRIVATE_LEAGUES_PARSED_OK )
			{
				try
				{
					plSync.onPostExecute(intent.getData());

					// cridar el handler amb el status private leagues parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.PRIVATE_LEAGUES_PARSED_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"Private leagues parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}
		
		// mirem si es algo referent al mercat
		// uri de /market -> action get content, descarregar tot
		if( MarketProvider.uriMatcher.match(uri) == MarketProvider.MARKET_PLAYERS &&
				Intent.ACTION_GET_CONTENT.equals(intent.getAction())	)
		{
			// get market players
			Log.d(TAG,"MarketSync amb jornada: "+nextJornada);
			
			// per defecte actualitzem amb jornada actual
			Integer day = jornada;
			// si estan canvis oberts, actualitzem amb next jornada
			if( status == Supermanager.OPEN_STATUS )
				day = nextJornada;

			// executem el sincronitzador
			MarketSync marketSync = new MarketSync(this, client, day);
			marketSync.execute();
			
			// si no hi ha error guardem a db
			if( marketSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( marketSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( marketSync.status == Supermanager.MARKET_PARSED_OK )
			{
				try
				{
					marketSync.onPostExecute(intent.getData());

					// cridar el handler amb el status market parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MARKET_PARSED_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"Market data parsed successfully!");
				}
				catch(ClosedChangesException e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CLOSED_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si es algo referent al mercat
		// uri de /market -> action get buy players, actualitza players a mostrar
		if( MarketProvider.uriMatcher.match(uri) == MarketProvider.MARKET_PLAYERS
			&& Supermanager.ACTION_GET_BUY_PLAYERS.equals(intent.getAction())	)
		{
			// get market players
			Log.d(TAG,"MarketSync buy players amb jornada: "+nextJornada);
			
			// per defecte actualitzem amb jornada actual
			Integer day = nextJornada;
			// si no estan canvis oberts, no fem res, no podem fer canvis
			if( status != Supermanager.OPEN_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CLOSED_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error in connection"); 
                } 
                
				Log.e(TAG,"Closed changes error!");
				return;
			}
			
			String idequ = intent.getStringExtra("cat.joronya.supermanager.market.idequ");
			String position = intent.getStringExtra("cat.joronya.supermanager.market.position");
			
			// executem el sincronitzador
			MarketSync marketSync = new MarketSync(this, client, day);
			marketSync.executeBuyMarket(idequ, position);
			
			// si no hi ha error guardem a db
			if( marketSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( marketSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( marketSync.status == Supermanager.MARKET_BUY_OK )
			{
				try
				{
					marketSync.onMarketBuyPostExecute(intent.getData());

					// cridar el handler amb el status market parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MARKET_BUY_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"Market data parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si es algo referent als equips
		// uri de /teams -> nomes updatem els llistat, no mirem action
		if( MyTeamsProvider.uriMatcher.match(uri) == MyTeamsProvider.MY_TEAMS )
		{
			// per defecte actualitzem amb jornada actual
			Integer day = nextJornada;
			
			// get my teams
			MyTeamsSync myTeamsSync = new MyTeamsSync(this, client, day);
			// si no hi ha error guardem a db
			myTeamsSync.execute();
			
			if( myTeamsSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( myTeamsSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( myTeamsSync.status == Supermanager.MY_TEAMS_PARSED_OK )
			{
				try
				{
					myTeamsSync.onPostExecute(intent.getData());

					// cridar el handler amb el status my teams parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MY_TEAMS_PARSED_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"My teams parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}
		
		// mirem si es algo referent al detall de l'equip amb action de get content
		if( MyTeamDetailProvider.uriMatcher.match(uri) == MyTeamDetailProvider.MY_TEAM_DETAIL 
				&& Intent.ACTION_GET_CONTENT.equals(intent.getAction()) )
		{
			String idequ = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.idequ");

			// per defecte actualitzem amb jornada actual
			Integer day = nextJornada;
			
			// get my team detail
			MyTeamDetailSync myTeamDetailSync = new MyTeamDetailSync(this, client, day);
			myTeamDetailSync.syncTeam(idequ);
			
			if( myTeamDetailSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.MY_TEAM_DETAIL_PARSED_OK )
			{
				try
				{
					myTeamDetailSync.onPostExecute(intent.getData());

					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MY_TEAM_DETAIL_PARSED_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"My teams parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si es algo referent al detall de l'equip amb action de reset changes
		if( MyTeamDetailProvider.uriMatcher.match(uri) == MyTeamDetailProvider.MY_TEAM_DETAIL 
				&& Supermanager.ACTION_RESET_CHANGES.equals(intent.getAction()) )
		{
			String idequ = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.idequ");
			
			// per defecte actualitzem amb jornada actual
			Integer day = nextJornada;
			
			// get my team detail
			MyTeamDetailSync myTeamDetailSync = new MyTeamDetailSync(this, client, day);
			myTeamDetailSync.resetChanges(idequ);
			
			if( myTeamDetailSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.MY_TEAM_DETAIL_RESET_CHANGES_OK )
			{
				try
				{
					myTeamDetailSync.onPostExecute(intent.getData());

					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MY_TEAM_DETAIL_RESET_CHANGES_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"My teams parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si es algo referent al detall de l'equip amb action de sell player
		if( MyTeamDetailProvider.uriMatcher.match(uri) == MyTeamDetailProvider.MY_TEAM_DETAIL 
				&& Supermanager.ACTION_SELL_PLAYER.equals(intent.getAction()) )
		{
			String idequ = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.idequ");
			String position = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.position");
			
			// per defecte actualitzem amb jornada actual
			Integer day = nextJornada;
			
			// get my team detail
			MyTeamDetailSync myTeamDetailSync = new MyTeamDetailSync(this, client, day);
			myTeamDetailSync.sellPlayer(idequ,position);
			
			if( myTeamDetailSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.MY_TEAM_DETAIL_SELL_OK )
			{
				try
				{
					myTeamDetailSync.onPostExecute(intent.getData());

					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MY_TEAM_DETAIL_SELL_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"My teams parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si es algo referent al detall de l'equip amb action de cancel player change
		if( MyTeamDetailProvider.uriMatcher.match(uri) == MyTeamDetailProvider.MY_TEAM_DETAIL 
				&& Supermanager.ACTION_CANCEL_PLAYER.equals(intent.getAction()) )
		{
			String idequ = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.idequ");
			String position = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.position");
			
			// per defecte actualitzem amb jornada actual
			Integer day = nextJornada;
			
			// get my team detail
			MyTeamDetailSync myTeamDetailSync = new MyTeamDetailSync(this, client, day);
			myTeamDetailSync.cancelChange(idequ,position);
			
			if( myTeamDetailSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.MY_TEAM_DETAIL_CANCEL_OK )
			{
				try
				{
					myTeamDetailSync.onPostExecute(intent.getData());

					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MY_TEAM_DETAIL_CANCEL_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"My teams parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si es algo referent al detall de l'equip amb action de sell player
		if( MyTeamDetailProvider.uriMatcher.match(uri) == MyTeamDetailProvider.MY_TEAM_DETAIL 
				&& Supermanager.ACTION_BUY_PLAYER.equals(intent.getAction()) )
		{
			String idequ = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.idequ");
			String position = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.position");
			String idjug = intent.getStringExtra("cat.joronya.supermanager.myteamdetail.idjug");
			
			// per defecte actualitzem amb jornada actual
			Integer day = nextJornada;
			
			// get my team detail
			MyTeamDetailSync myTeamDetailSync = new MyTeamDetailSync(this, client, day);
			myTeamDetailSync.buyPlayer(idequ,position,idjug);
			
			if( myTeamDetailSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( myTeamDetailSync.status == Supermanager.MY_TEAM_DETAIL_BUY_OK )
			{
				try
				{
					myTeamDetailSync.onPostExecute(intent.getData());

					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.MY_TEAM_DETAIL_BUY_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"My teams parsed successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si volem la cerca de lligues privades per texte
		if( PrivateLeagueProvider.uriMatcher.match(uri) == PrivateLeagueProvider.PRIVATE_LEAGUES 
			&& Supermanager.ACTION_SEARCH_PRIVATE_LEAGUE_WITH_TEXT.equals(intent.getAction()) )
		{
			String search = intent.getStringExtra("cat.joronya.supermanager.privateleague.search");
			
			// get my team detail
			PrivateLeaguesSearchSync privateLeagueSearchSync = new PrivateLeaguesSearchSync(this, client);
			privateLeagueSearchSync.searchWithText(search);
			
			if( privateLeagueSearchSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( privateLeagueSearchSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( privateLeagueSearchSync.status == Supermanager.PRIVATE_LEAGUE_SEARCH_OK )
			{
				try
				{
					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.PRIVATE_LEAGUE_SEARCH_OK); 
	                data.putSerializable(Supermanager.PRIVATE_LEAGUE_SEARCH_RESULTS, privateLeagueSearchSync.privateLeagues);
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"Private leagues found successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si volem la cerca de lligues privades per grup
		if( PrivateLeagueProvider.uriMatcher.match(uri) == PrivateLeagueProvider.PRIVATE_LEAGUES 
			&& Supermanager.ACTION_SEARCH_PRIVATE_LEAGUE_WITH_GROUP.equals(intent.getAction()) )
		{
			String group = intent.getStringExtra("cat.joronya.supermanager.privateleague.group");
			
			// get my team detail
			PrivateLeaguesSearchSync privateLeagueSearchSync = new PrivateLeaguesSearchSync(this, client);
			privateLeagueSearchSync.searchWithGroup(group);
			
			if( privateLeagueSearchSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( privateLeagueSearchSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( privateLeagueSearchSync.status == Supermanager.PRIVATE_LEAGUE_SEARCH_OK )
			{
				try
				{
					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.PRIVATE_LEAGUE_SEARCH_OK); 
	                data.putSerializable(Supermanager.PRIVATE_LEAGUE_SEARCH_RESULTS, privateLeagueSearchSync.privateLeagues);
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"Private leagues found successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si volem incriure'ns a la lliga privada
		if( PrivateLeagueProvider.uriMatcher.match(uri) == PrivateLeagueProvider.PRIVATE_LEAGUES 
			&& Supermanager.ACTION_JOIN_PRIVATE_LEAGUE.equals(intent.getAction()) )
		{
			String idpri = intent.getStringExtra("cat.joronya.supermanager.privateleague.idpri");
			String ideqs = intent.getStringExtra("cat.joronya.supermanager.privateleague.ideqs");
			String clave = intent.getStringExtra("cat.joronya.supermanager.privateleague.clave");
			
			// get my team detail
			PrivateLeaguesJoinSync privateLeagueJoinSync = new PrivateLeaguesJoinSync(this, client);
			privateLeagueJoinSync.join(idpri, ideqs, clave);
			
			if( privateLeagueJoinSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( privateLeagueJoinSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			// qualsevol altre status: PRIVATE_LEAGUE_JOIN_OK, PRIVATE_LEAGUE_WRONG_PASSWORD,
			// PRIVATE_LEAGUE_MAX_TEAM_REACHED, PRIVATE_LEAGUE_MAX_TEAM_PER_PLAYER_REACHED
			else
			{
				try
				{
					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, privateLeagueJoinSync.status); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"Private league joined successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

		// mirem si volem crear una lliga privada
		if( PrivateLeagueProvider.uriMatcher.match(uri) == PrivateLeagueProvider.PRIVATE_LEAGUES 
			&& Supermanager.ACTION_CREATE_PRIVATE_LEAGUE.equals(intent.getAction()) )
		{
			String nombre = intent.getStringExtra("cat.joronya.supermanager.privateleague.nombre");
			String limite = intent.getStringExtra("cat.joronya.supermanager.privateleague.limite");
			String limiteeq = intent.getStringExtra("cat.joronya.supermanager.privateleague.limiteeq");
			String clave = intent.getStringExtra("cat.joronya.supermanager.privateleague.clave");
			String clave2 = intent.getStringExtra("cat.joronya.supermanager.privateleague.clave2");
			String emails = intent.getStringExtra("cat.joronya.supermanager.privateleague.emails");
			
			// get my team detail
			PrivateLeaguesCreateSync privateLeaguesCreateSync = new PrivateLeaguesCreateSync(this, client);
			privateLeaguesCreateSync.join(nombre, limite, limiteeq, clave, clave2, emails);
			
			if( privateLeaguesCreateSync.status == Supermanager.CONNECTIVITY_ERROR_STATUS )
			{
				// cridar el handler amb el status de connectivity error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.CONNECTIVITY_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Connectivity error!");
				return;
			}
			else if( privateLeaguesCreateSync.status == Supermanager.OTHER_ERROR_STATUS )
			{
				// cridar el handler amb el status de other unknown error
				Message msg = Message.obtain(); 
                Bundle data = new Bundle(); 
                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
                msg.setData(data); 
                
                try{ 
                    messenger.send(msg); 
                }catch(RemoteException e){ 
                    Log.e(TAG, "Error sending auth error to Activity caller"); 
                } 
                
				Log.e(TAG,"Other error!");
				return;
			}
			else if( privateLeaguesCreateSync.status == Supermanager.PRIVATE_LEAGUE_CREATE_OK )
			{
				try
				{
					// cridar el handler amb el status my team detail parsed successfully
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.PRIVATE_LEAGUE_CREATE_OK); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException e){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.d(TAG,"Private league created successfully!");
				}
				catch(Exception e)
				{
					// cridar el handler amb el status de other unknown error
					Message msg = Message.obtain(); 
	                Bundle data = new Bundle(); 
	                data.putInt(Supermanager.STATUS_MESSAGE, Supermanager.OTHER_ERROR_STATUS); 
	                msg.setData(data); 
	                
	                try{ 
	                    messenger.send(msg); 
	                }catch(RemoteException re){ 
	                    Log.e(TAG, "Error sending auth error to Activity caller"); 
	                } 
	                
					Log.e(TAG,"Other error!");
				}
				
				return;
			}
		}

	}
	
}